// SPDX-FileCopyrightText: 2023 CASTest Corporation Limited
// SPDX-License-Identifier: LGPL-v3

#ifndef ICTEST_ATPGENGINE_H
#define ICTEST_ATPGENGINE_H

#include "atpg/ATPGCommons.h"
#include "atpg/SAFTest.h"
#include "fault/SAF.h"
#include "fault/SAFList.h"
#include "netlist/PrimNetlist.h"
#include "pattern/Pattern.h"
#include "simulation/SimEngine.h"
#include "util/TimeUtil.h"

namespace ictest {

// ATPG执行引擎
class ATPGEngine {
public:
  ATPGEngine(PrimNetlist *prim, SimEngine *sim, SAFList *saf_list,
             std::string dump_path, Option *global_option) {
    prim_ = prim;
    sim_ = sim;
    saf_list_ = saf_list;
    dump_path_ = std::move(dump_path);
    global_option_ = global_option;
  }

  ~ATPGEngine() = default;

  // ====================================================================
  //                SINGLE FAULT TEST ATPG ENGINE
  // ====================================================================
  void GenerateTestPatternForEveryFaultInList();

  // ====================================================================
  //                        ATPG REPORT DUMP
  // ====================================================================
  void DumpSAFList();
  static void ReportSAFaultStatistics(
      std::vector<SAF *> &saflist,
      const std::string &meg = "Stuck-at Fault Summary Report");

  // ====================================================================
  //                          Pattern Handler
  // ====================================================================
  void GenerateSCPatForSA(SAFTest *saf_test_generator,
                          std::vector<std::vector<int>> &atpg_sc_pat);

  void GeneratePIPatForSA(SAFTest *saf_test_generator,
                          std::vector<std::vector<int>> &atpg_pi_pat);

  void GenerateFinalSCPatternForSimulation(
      std::vector<std::vector<std::vector<int>>> &atpg_sc_pats);

private:
  PrimNetlist *prim_;
  SimEngine *sim_;
  SAFList *saf_list_;
  std::string dump_path_;
  Option *global_option_;
};
} // namespace ictest

#endif // ICTEST_ATPGENGINE_H
